<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/common/common.jsp"%>
<%@ include file="/common/header.jsp"%>
<title><spring:message code="index.Haixuebang"/></title>
</head>
<body onload="onloadMess();">
<div class="ct-login">
	<div class="ct-login-bg">
    	<div class="ct-login-mid">
        	<div class="login-box">
            	<div class="box-top">
                	<span id="login1" class="box-checked"><spring:message code="log.MemberLogin"/></span>
                    <div class="clear"></div>
                </div>
                <form id="ff" 
				action="${pageContext.request.contextPath}/login.action"
				method="post">
                <ul class="box-cen dp1">
                    <div id="alert_info" class="alert_in"></div>
                    </br>
                	<li><b class="cen1"></b>
                		<input type="hidden" name="projectId" value="${projectId }"/>
                	   <input type="text" id="userAccount" name="userAccount"  maxlength="32"  class="login-ipt"  value="${user.userAccount}"  placeholder="<spring:message code="log.Pleaseenteraccount"/>" />
                	</li>
                	<li><b class="cen2"></b>
                	<input type="password"  id="tpassword" name="tpassword"    maxlength="32"  class="login-ipt" value="${user.upassword}"  placeholder="<spring:message code="log.Pleaseenterpassword"/>" />
                	</li>
                	<li>
                	<b class="cen5"></b>
                	<input type="text"  id="safeCode" name="safeCode"    maxlength="4" class="login-ipt" value="${safeCode}" autocomplete="off"  placeholder="<spring:message code="log.Pleaseenterverificationcode"/>" />
                	</li>
                	<li>
                	<b class="cen4"></b>
                <img id="showCode" onclick="refreshCode()" src="${base}/getCheckCode.action" width="100px" height="32px" style="margin-left:10px;" alt="" />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <a id="aRecode" href="javascript:void(0);" onclick="refreshCode()">&nbsp;<spring:message code="log.ChangeAnotherPicture"/></a>  </li>
                    <li class="no">
                      <input id="queryBtn"  type="submit" class="subbtn" value=""   style="display: none"/>
                      <a href="#"  onclick="submitForm();" class="cen4"><spring:message code="log.Confirm"/></a>
                    </li>
                    <li class="no">
                    	    <input type="checkbox" id="setflag"   name="setflag" value="" /><spring:message code="log.RememberAccount"/>
                            
                    </li>
                    <li class="no">
                    	    
                            <a href="${base}/regist/toregist.action" class="cen5 le"><spring:message code="log.RegisterNow"/></a>
                            <a href="${base}/regist/toBackp.action" class="cen5"><spring:message code="log.ForgetPassword"/></a>
                    </li>
                </ul>
                <input type="hidden" id="message" name="message" value="${message}"/>
                <input type="hidden" id="upassword" name="upassword"/>
                </form>
            </div>
        </div>
    </div>
</div>

	<script type="text/javascript">
	
	//设置text需要验证
	  $(function () {
		  refreshCode();
		   if (window != window.top){
			  window.top.document.location.href = Jroot+ "/loginInit.action";
		  } 
		   
		  if (!isPlaceholder()) {//不支持placeholder 用jquery来完成
				setTimeout("placeholderText()",200);	 
		  }
	  });
	  
	  function refreshCode(imgObj){
		  if (!imgObj) {
				imgObj = document.getElementById("showCode");
			}
			var index = imgObj.src.indexOf("?");
			if(index != -1) {
				var url = imgObj.src.substring(0,index + 1);
				imgObj.src = url + Math.random();
			} else {
				imgObj.src = imgObj.src + "?" + Math.random();
			}
	  }
	  

	    function onloadMess(){
	    	refreshCode();
	    	var message=$('#message').val();
	    	if(message!=''){
	    		$('#alert_info').html(message);
	    	}
            var userAccount=getCookie("userAccount");
	    	
	    	if(userAccount!=''&&userAccount!= "undefined"){
	    		$('#userAccount').val(userAccount);
	    		document.getElementById("setflag").checked=true;
	    	}
	    }
	   
		function submitForm() {
			var setflag=document.getElementById("setflag");
			var userAccount=$('#userAccount').val();
			var password=$('#tpassword').val();
			 var safeCode=$('#safeCode').val(); 
			 if(userAccount=='' || $('#userAccount').val()==$('#userAccount').attr("placeholder")){
				 $('#alert_info').html('请输入账号!');
				 $('#userAccount').focus();
		    	   return;
		      }
			 if(password==''){
				 $('#alert_info').html('请输入密码!');
				 $('#tpassword').focus();
		    	   return;
		      }
			 if(safeCode=='' || $('#safeCode').val()==$('#safeCode').attr("placeholder")){
				 $('#alert_info').html('请输入验证码!');
				 $('#safeCode').focus();
		    	   return;
		      } 
			 var reg = /^1[3|4|5|6|7|8|9]\d{9}$/;
			 var reg1 = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
			 if(!reg.test(userAccount)&&!reg1.test(userAccount)){
				 $('#alert_info').html('账号必须是手机号或是邮箱，不满足要求');
				 $('#userAccount').focus();
		    	   return;
			 }
			 if (!/^[\w]+$/.test(password)) {
				 $('#alert_info').html('密码只能数字、字母、下划线组成.');
    			 $('#tpassword').focus();
  	    	   return;
			 }
    	 	 if (!/^[0-9a-zA-Z]*$/g.test(safeCode)) {
    			 $('#alert_info').html('验证码只能数字、字母组成.');
    			 $('#safeCode').focus();
  	    	   return;
			 }	 
			 if(setflag.checked){
				 var expdate = new Date(); 
				 expdate.setTime(expdate.getTime() + 168 * (24 * 60 * 60 * 1000));
				 SetCookie("userAccount",$('#userAccount').val(),expdate);
			 }else{
				 SetCookie("userAccount",'',expdate);
			 }

	     		//密码加密  gzq201511-12
	 			RSAUtils.setMaxDigits(200);
	 			var key = new RSAUtils.getKeyPair("${publicKeyExponent}", "", "${publicKeyModulus}");
	 			var tmpstrpas = password.split("").reverse().join("");
	 			var encrypedPwd = RSAUtils.encryptedString(key,tmpstrpas);
	 			$('#upassword').val(encrypedPwd);
	     		//密码加密  gzq201511-12end
	     		
				$('#ff').submit();
			
		}
		function SetCookie(name, value, expires) 
		{ 
		var argv = SetCookie.arguments; 
		//本例中length = 3 
		var argc = SetCookie.arguments.length; 
		var expires = (argc > 2) ? argv[2] : null; 
		var path = (argc > 3) ? argv[3] : null; 
		var domain = (argc > 4) ? argv[4] : null; 
		var secure = (argc > 5) ? argv[5] : false; 
		document.cookie = name + "=" + escape (value) + 
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
		((path == null) ? "" : ("; path=" + path)) + 
		((domain == null) ? "" : ("; domain=" + domain)) + 
		((secure == true) ? "; secure" : ""); 
		} 
		function getCookie(c_name)
		{
		if (document.cookie.length>0)
		  {
		  c_start=document.cookie.indexOf(c_name + "=")
		  if (c_start!=-1)
		    { 
		    c_start=c_start + c_name.length+1 
		    c_end=document.cookie.indexOf(";",c_start)
		    if (c_end==-1) c_end=document.cookie.length
		    return unescape(document.cookie.substring(c_start,c_end))
		    } 
		  }
		return ""
		}
		
		//jQuery placeholder, fix for IE6,7,8,9
	    //判断浏览器是否支持 placeholder属性
		function isPlaceholder(){
		 	var input = document.createElement('input');
		 	return 'placeholder' in input;
		}
		
		function placeholderText(){
			if(!isPlaceholder()){
		         $("input[type='text']").each(//把input绑定事件 排除password框
		             function(){
		        	 	 /*if($(this).val() != "" && $(this).val()!=$(this).attr("placeholder")){
		        	 		$(this).css("color","000000");	
		        	 	 }else{
		        	 		$(this).css("color","#A9A9A9");
		        	 	 }*/
		        	 	
		                 if($(this).attr("placeholder")!=""){
		                	 if($(this).val() == ""){
			                     $(this).val($(this).attr("placeholder"));
		                	 }
		                     $(this).focus(function(){
		                         if($(this).val()==$(this).attr("placeholder")){
			                         $(this).val("");
			                         //$(this).css("color","000000");	                        	 
		                         } 
		                     });
		                     $(this).blur(function(){
		                         if($(this).val()==""){
			                       	 $(this).val($(this).attr("placeholder"));
			                         //$(this).css("color","#A9A9A9");	                        	 
		                         } 
		                     });
		                 }
		         });
		         //对password框的特殊处理1.创建一个text框 2获取焦点和失去焦点的时候切换	        	         
		         var pwdField = $("input[type=password]");
		         var pwdVal  = pwdField.attr('placeholder');
		         pwdField.after("<input id='pwdPlaceholder' type='text' class='login-ipt' value="+pwdVal+" autocomplete='off' />");
		         var pwdPlaceholder = $('#pwdPlaceholder');
		         if(pwdField.val() == ""){
			         pwdPlaceholder.show();
			         pwdField.hide();
		         }else{
		        	 pwdPlaceholder.hide();
			          pwdField.show(); 
		         }
		         //pwdField.css("color","000000");
		         //pwdPlaceholder.css("color","#A9A9A9");
		         
		         pwdPlaceholder.focus(function(){
		          pwdPlaceholder.hide();
		          pwdField.show();
		          pwdField.focus();
		         });
		         
		         pwdField.blur(function(){
		          if(pwdField.val() == '') {
		           pwdPlaceholder.show();
		           pwdField.hide();
		          }
		         });
		         
		     }
		}
	</script>

</body>
<%@ include file="/common/footer.jsp"%>
</html>